package com.smarttest.portal.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.smarttest.portal.mapper.DbAutoEnvironmentMapper;
import com.smarttest.portal.mapper.DbAutoLocalinterfaceMapper;
import com.smarttest.portal.mapper.DbAutoTesturlMapper;
import com.smarttest.portal.pojo.DbAutoEnvironment;
import com.smarttest.portal.pojo.DbAutoEnvironmentExample;
import com.smarttest.portal.pojo.DbAutoLocalinterface;
import com.smarttest.portal.pojo.DbAutoLocalinterfaceExample;
import com.smarttest.portal.pojo.DbAutoLocalinterfaceExample.Criteria;
import com.smarttest.portal.service.AddInterfaceService;
@Service
public class AddInterfaceServiceImpl implements AddInterfaceService {
	@Autowired
	private DbAutoLocalinterfaceMapper DbAutoLocalinterfaceMapper;
	@Autowired
	private DbAutoEnvironmentMapper DbAutoEnvironmentMapper;
	@Override
	public int addInterface(String name, String params) {
		// TODO Auto-generated method stub
		DbAutoLocalinterface dl = new DbAutoLocalinterface();
		dl.setName(name);
		dl.setParam(params);
		dl.setSelfdefined(true);
		return DbAutoLocalinterfaceMapper.insert(dl);
	}
	@Override
	public int getExistingInterface(String name) {
		// TODO Auto-generated method stub
		DbAutoLocalinterfaceExample example = new DbAutoLocalinterfaceExample();
		Criteria critera = example.createCriteria();
		critera.andNameEqualTo(name);
		List<DbAutoLocalinterface> l = DbAutoLocalinterfaceMapper.selectByExample(example);
		return l.size();
	}
	@Override
	public List<DbAutoLocalinterface> getLocalInterface() {
		// TODO Auto-generated method stub
		List<DbAutoLocalinterface> l = DbAutoLocalinterfaceMapper.selectByExampleWithBLOBs(new DbAutoLocalinterfaceExample());
		return l;
	}
	@Override
	public List<DbAutoLocalinterface> getLocalInterfaceDetails(int id) {
		// TODO Auto-generated method stub
		DbAutoLocalinterfaceExample example = new DbAutoLocalinterfaceExample();
		Criteria critera = example.createCriteria();
		critera.andIdEqualTo(id);
		List<DbAutoLocalinterface> l = DbAutoLocalinterfaceMapper.selectByExampleWithBLOBs(example);
		return l;
	}
	@Override
	public String getTestUrl() {
		// TODO Auto-generated method stub
		List<DbAutoEnvironment> l = DbAutoEnvironmentMapper.selectByExample(new DbAutoEnvironmentExample());	
		String urlstr = "";
		
		for (DbAutoEnvironment dbAutoEnvironment : l) {
			int env = dbAutoEnvironment.getId();
			if (dbAutoEnvironment.getId() == 3) {
				urlstr += "<option selected=\"selected\" value="+env+">"+dbAutoEnvironment.getDetail()+"</option>";
			}
			else {
				urlstr += "<option value=\""+env+"\">"+dbAutoEnvironment.getDetail()+"</option>";
			}
		}
		return urlstr;
	}
	@Override
	public List<DbAutoEnvironment> getTestUrlData() {
		// TODO Auto-generated method stub
		List<DbAutoEnvironment> result = DbAutoEnvironmentMapper.selectByExample(new DbAutoEnvironmentExample());
		return result;
	}
}
